<template>
	<view>
		<!--二维码扫码进入页面-->
	</view>
</template>

<script>
	export default {
		onLoad() {
			var me = this
			var role = uni.getStorageSync('ROLE'); //获取
			console.log("role=" + role)
			if (!role) {
				uni.redirectTo({
					url: 'index'
				})
			} else if (role == '1') {
				uni.scanCode({
					success: (res) => {
						var path = res.path
						var scene = path.substring(path.indexOf('scene=') + 6)
						console.log(scene)

						uni.request({
							url: me.$ServerUrl +
								'/invoice/api/qrcode/getMerchantIdByContent', //根据二维码内容二维码详情
							data: {
								content: scene
							},
							header: {
								'content-type': 'application/json'
							},
							method: "GET",
							success: (res) => {
								console.log('二维码热热热热热若若若若若若' + JSON.stringify(res))
								me.merchant = res.data.merchant //商家信息
								if (!me.merchant) {
									//没有商家id
									uni.showModal({
										content: '不好意思，该二维码没有存在商家',
										showCancel: false,

									});
								} else {
									//存在二维码
									//在tabBer里面
									console.log('存在二维码二维码')
									uni.redirectTo({
										url: '/pages/user/scan/billing'
									})
								}
							},
						})
					},
				})
			} else if (role == '2') {
				var id = uni.getStorageSync("merchantInfo").id
				console.log(id)
				var merchantName = uni.getStorageSync("merchantInfo").merchantName
				if (!merchantName) {
					uni.redirectTo({
						url: 'business/mine/perferctUser/perfectUser'
					})
				} else {
					uni.request({
						url: me.$ServerUrl + '/invoice/api/qrcode/getQrcodeByMerchantId', //根据商家ID查询二维码内容
						data: {
							merchantId: id
						},
						header: {
							'content-type': 'application/json'
						},
						method: "GET",
						success: (res) => {
							console.log('res=' + JSON.stringify(res))
							//如果商家没有绑定二维码，则跳转至绑定页面
							if (!res.data) {
								uni.redirectTo({
									url: '/pages/business/mine/mine-business/index'
								})
							} else {
								//提示框
								uni.showModal({
									title: '提示',
									content: '已绑有二维码,是否需要解绑',
									success: function(res) {
										if (res.confirm) {
											//用户点击确认，跳转至用户二维码
											uni.redirectTo({
												url: '/pages/business/mine/mine-business/index'
											});
										} else if (res.cancel) {
											//用户点击取消，跳转至商家首页
											uni.redirectTo({
												url: '/pages/business/mine/index'
											});
											console.log('用户点击取消');
										}
									}
								});
							}
						}
					})
				}
				//不在tabBer里面
				// uni.redirectTo({
				// 	url: '/pages/business/mine/mine-business/index'
				// });
			}
		},
		methods: {

		}
	}
</script>

<style>

</style>
